package net.zjitc;

import net.zjitc.annotation.ResultMapping;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;

/**
 * Created by Administrator on 2017/11/6.
 */
public class TestFour {
    @ResultMapping
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException {
        String packgeName = "net.zjitc.ex01";
        String pathName = packgeName.replace(".","/");
        URL resource = Thread.currentThread().getContextClassLoader().getResource(pathName);
        System.out.println(resource.getPath());
        System.out.println("-------------");
        File file = new File(resource.getPath());
        File[] files = file.listFiles();
        for (File f:files) {
            System.out.println(f.getName());
            String className = f.getName();
            className = packgeName+'.'+className.substring(0,className.length()-6);
            System.out.println(className);

            Class clazz = Class.forName(className);
            clazz.newInstance();
            System.out.println(clazz.newInstance());
            System.out.println("-------------");

            //方法
            Method[] methods = clazz.getMethods();
            for (Method m: methods) {
                /*System.out.println(m.getName());*/
                if(m.getName().equals("speak")){
                    m.invoke(clazz.newInstance(),"zs",20);
                }
            }
            /*//构造函数
            Constructor[] constructors = clazz.getConstructors();
            for (Constructor c: constructors) {
                System.out.println(c);
            }*/

        }
    }
}
